package com.group.mall.controller;

import com.group.mall.domain.DTO.AddressDTO;
import com.group.mall.domain.POJO.Address;
import com.group.mall.service.AddressService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigInteger;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/address")
public class AddressController {

    @Autowired
    private AddressService addressService;

    /*
    查询
     */
    @GetMapping("/query")
    public List<Address> list(Long userId) {
        log.info("查询用户{}地址", userId);
        List<Address> addressList = addressService.getAddress(userId);
        return addressList;
    }
    /*
    删除
     */
   @GetMapping("/deleteAddress")
    public void delete(Long id){
        log.info("删除用户{}地址",id);
        addressService.deleteAddress(id);
    }
    /*
    删除全部
     */
    @GetMapping ("/deleteAll")
    public void deleteAll(Long userId){
        addressService.deleteAllAddress(userId);
    }
    /*
    新增
     */
    @PostMapping("/add")
    public void add( AddressDTO addressDTO){
        addressService.addAddress(addressDTO);
    }
    /*
    修改
     */
    @PostMapping("/update")
    public void update(AddressDTO addressDTO){
        addressService.updateAddress(addressDTO);
    }

}
